//version: 1.0.2 
package roster;

public class Schedule{
	public static final int maxNoStaffs=100;
	private int noOfRecords;
	private String name;
	private int startDate;//start day of the week
	public static final int noOfDays=7;
	private String[] staffName;
	private String[][] time;//time[staffNameid][dateid]

	public Schedule(String name, int date){
		noOfRecords = 0;
		this.name = name;
		startDate = date;
		staffName = null;
		time = null;
	}

	public Schedule(int nRecs, String name, int d ,String[] sname, String[][] t){
		noOfRecords = nRecs;
		this.name=name;
		startDate = d;
		staffName = sname;
		time = t;
	}
	
	public int getNoOfRecords(){
		return noOfRecords;
	}
	
	public String getName(){
		return name;
	}
	
	public int getStartDate(){
		return startDate;
	}

	public String[] getStaffName(){
		return staffName;
	}

	public String[][] getTime(){
		return time;
	}
	
	public void setName(String name){
		this.name=name;
	}

	public void setStartDate(int d){
		startDate=d;
	}
	
	public void setStaffName(int i, String inName){
		staffName[i]=inName;		
	}
	
	public void setTime(int i,int j, String time){
		this.time[i][j]=time;
	}	

	public void addStaff(String name){
		String[] newStaffs=new String[noOfRecords+1];
		for(int i=0;i<noOfRecords;i++){
			newStaffs[i]=staffName[i];
		}
		newStaffs[noOfRecords]=name;
		staffName=newStaffs;
		
		String[][] newTime=new String[noOfRecords+1][noOfDays];
		for(int i=0;i<noOfRecords;i++){
			for(int j=0;j<noOfDays;j++)
				newTime[i][j]=time[i][j];
		}
		for(int i=0;i<noOfDays;i++)
			newTime[noOfRecords][i]="-";
		time=newTime;
		
		noOfRecords++;
	}	
	
	public void deleteRecord(int row){
		for(int i=row; i<noOfRecords-1; i++){
			this.staffName[i]=this.staffName[i+1];
			this.time[i]=this.time[i+1];
		}
		noOfRecords--;
	}		
	
	public String toString()
	{	
		String str;
		str = "Schedule Name: " + name + "			No. of Staffs: " + noOfRecords + "\n" +
			  "Start date of the week: " + startDate/1000000 +"/" + startDate%1000000/10000 +"/" + startDate%10000 + "\n" +
			 //1234567890123456789 
			  "       Col(j)   ";
		for(int i=0; i<noOfDays; i++){
			str += String.format("%-7s", i+1);
		}
		str += "\nRow(i) Name     Mon    Tue    Wed    Thu    Fri    Sat    Sun";
		for(int i=0; i<noOfRecords; i++){
			str+="\n" + String.format("%-7s", i+1) + String.format("%-9s", staffName[i]);
			for(int j=0;j<noOfDays;j++){
				str+=String.format("%-7s", time[i][j]);
			}
		}
		return str;
	}
}